import Vue from 'vue'
import Vuex from 'vuex'
import { getItem, setItem, removeItem } from '@/utils/storage'

Vue.use(Vuex)

const tokenKey = 'token'
export default new Vuex.Store({
  state: {
    user: getItem(tokenKey)
  },
  mutations: {
    setUser (state, user) {
      state.user = user
      // window.localStorage.setItem('token', JSON.stringify(user))
      setItem(tokenKey, state.user)
    },
    rmUser (tokenKey) {
      removeItem(tokenKey)
    }
  },
  actions: {
  },
  modules: {
  }
})
